package com.zh.note.huawei.twohundred.Boss的收入;

/**
 * https://dream.blog.csdn.net/article/details/130837717
 * 5
 * 1 0 100
 * 2 0 199
 * 3 0 200
 * 4 0 200
 * 5 0 200
 */

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        // 存储上下级关系，key是上级，value是他有哪些下级
        Map<Integer, List<Integer>> graph = new HashMap<>();
        //存储级别id,和工资
        Map<Integer, Integer> moneyMap = new HashMap<>();
        Set<Integer> visitedNodes = new HashSet<>();

        for (int i = 0; i < n; i++) {
            if (!scanner.hasNext()) {
                break;
            }
            int nodeId = scanner.nextInt();
            int parentNodeId = scanner.nextInt();
            int amount = scanner.nextInt();
            moneyMap.put(nodeId, amount);

            List<Integer> children = graph.getOrDefault(parentNodeId,
                    new LinkedList<>());
            children.add(nodeId);
            graph.put(parentNodeId, children);

            visitedNodes.add(nodeId);
        }
        // 找到boss的ID
        int bossId = findRootNode(graph, visitedNodes);

        int totalMoney = calculateTotalMoney(bossId, graph, moneyMap);
        System.out.println(bossId + " " + totalMoney);
    }

    private static int findRootNode(Map<Integer, List<Integer>> graph, Set<Integer> visitedNodes) {
        int rootId = -1;
        for (Integer nodeId : graph.keySet()) {
            if (!visitedNodes.contains(nodeId)) {
                rootId = nodeId;
                break;
            }
        }
        return rootId;
    }

    private static int calculateTotalMoney(int nodeId, Map<Integer, List<Integer>> graph, Map<Integer, Integer> moneyMap) {
        if (!graph.containsKey(nodeId)) {
            return (int) (moneyMap.get(nodeId) / 100) * 15;
        }
        // 获取当前nodeId有哪些下级
        List<Integer> children = graph.get(nodeId);
        int totalMoney = 0;
        //计算下级提成的工资
        for (int i = 0; i < children.size(); i++) {
            int childNodeId = children.get(i);
            totalMoney += calculateTotalMoney(childNodeId, graph, moneyMap);
        }
        //计算他本身的工资
        if (moneyMap.containsKey(nodeId)) {
            totalMoney += moneyMap.get(nodeId);
            return (int) (totalMoney / 100) * 15;
        }

        return totalMoney;
    }
}

